namespace Training7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String filePath = @"D:\Documents\test.txt";

            try
            {
                using(StreamWriter writer= new StreamWriter(filePath))
                {
                    writer.WriteLine(textBox1.Text);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            String filePath = @"D:\Documents\test.txt";
            if(File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
    }
}